/*
* jlb
*/
package com.jlb.jlb.ctrl;

import com.alibaba.fastjson.JSON;
import com.jlb.core.entity.BeanRet;
import com.jlb.core.entity.Page;
import com.jlb.core.tools.StringTools;
import com.jlb.core.tools.redis.RedisUtils;
import com.jlb.jlb.entity.JlbOreLog;
import com.jlb.jlb.service.JlbOreLogSV;
import com.jlb.user.entity.User;
import com.jlb.user.service.UserSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * 金兰宝矿石转账记录 控制器
 *
 * @author jlb
 */
@RestController
@RequestMapping("/jlbOreLog")
@Slf4j
@Api(value = "金兰宝矿石转账记录控制器", description = "金兰宝矿石转账记录控制器")
public class JlbOreLogCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private JlbOreLogSV jlbOreLogSV;

    @Resource
    private UserSV userSV;

    /**
     * 查询JlbOreLog一个详情信息
     *
     * @param id
     * @param outUserCode 转出账户编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询JlbOreLog一个详情信息", notes = "查询JlbOreLog一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "outUserCode", value = "转出账户编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public BeanRet load(Long id, String outUserCode) {
        if (id == null) {
            return null;
        }
        if (outUserCode == null) {
            return null;
        }
        JlbOreLog jlbOreLog = jlbOreLogSV.load(id, outUserCode);
        log.info(JSON.toJSONString(jlbOreLog));
        return BeanRet.create(true, "查询成功", jlbOreLog);
    }


    /**
     * 根据条件id查询JlbOreLog一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询JlbOreLog一个详情信息", notes = "查询JlbOreLog一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public BeanRet loadById(@PathVariable Long id) {
        if (id == null) {
            return null;
        }
        JlbOreLog jlbOreLog = jlbOreLogSV.loadById(id);
        log.info(JSON.toJSONString(jlbOreLog));
        return BeanRet.create(true, "查询成功", jlbOreLog);
    }

    /**
     * 根据条件outUserCode查询JlbOreLog一个详情信息
     *
     * @param outUserCode 转出账户编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询JlbOreLog一个详情信息", notes = "查询JlbOreLog一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "outUserCode", value = "转出账户编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/outUserCode/{outUserCode}")
    @ResponseBody
    public BeanRet loadByOutUserCode(@PathVariable String outUserCode) {
        if (outUserCode == null) {
            return null;
        }
        JlbOreLog jlbOreLog = jlbOreLogSV.loadByOutUserCode(outUserCode);
        log.info(JSON.toJSONString(jlbOreLog));
        return BeanRet.create(true, "查询成功", jlbOreLog);
    }


    /**
     * 查询JlbOreLog信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询JlbOreLog信息集合", notes = "查询JlbOreLog信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "account", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "createTimeBegin", value = "转账时间", paramType = "query"),
            @ApiImplicitParam(name = "createTimeEnd", value = "转账时间", paramType = "query")
    })
    @GetMapping(value = "/list")
    @ResponseBody
    public BeanRet list(String account, @ApiIgnore JlbOreLog jlbOreLog, Integer curPage, Integer pageSize) {
        Page<JlbOreLog> page = new Page<JlbOreLog>(pageSize, curPage);
        if (StringTools.isNotEmpty(account)) {
            User user = userSV.loadByAccount(account);
            if (user == null) {
                return BeanRet.create(true, "查询成功", page);
            }
            jlbOreLog.setInUserCode(user.getCode());
            jlbOreLog.setOutUserCode(user.getCode());
        }
        List<JlbOreLog> jlbOreLogs = jlbOreLogSV.list(jlbOreLog, page.genRowStart(), page.getPageSize());
        page.setVoList(jlbOreLogs);
        int total = jlbOreLogSV.count(jlbOreLog);
        page.setTotalRow(total);

        return BeanRet.create(true, "查询成功", page);

    }


    /**
     * 查询JlbOreLog信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询JlbOreLog信息集合", notes = "查询JlbOreLog信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "outUserCode", value = "转出账户编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public BeanRet listByPk(Long id, String outUserCode, Integer curPage, Integer pageSize) {
        Page<JlbOreLog> page = new Page<JlbOreLog>(pageSize, curPage);
        List<JlbOreLog> jlbOreLogs = jlbOreLogSV.list(id, outUserCode, page.genRowStart(), page.getPageSize());
        page.setVoList(jlbOreLogs);
        int total = jlbOreLogSV.count(id, outUserCode);
        page.setTotalRow(total);

        return BeanRet.create(true, "查询成功", page);
    }

    /**
     * 统计JlbOreLog信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计JlbOreLog信息数量根据主键", notes = " 统计JlbOreLog信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "outUserCode", value = "转出账户编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(Long id, String outUserCode) {
        return jlbOreLogSV.count(id, outUserCode);
    }

    /**
     * 统计JlbOreLog信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计JlbOreLog信息数量", notes = "统计JlbOreLog信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "outUserCode", value = "转出账户编码", paramType = "query"),
            @ApiImplicitParam(name = "inUserCode", value = "转入账户编码", paramType = "query"),
            @ApiImplicitParam(name = "num", value = "数量", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "类型 金兰宝  JLB ,矿石 ORE", paramType = "query"),
            @ApiImplicitParam(name = "event", value = "事件：转账 Transfer，复投 Re_Cast，押金 Deposit，押金返还 Deposit_Return", paramType = "query"),
            @ApiImplicitParam(name = "beforeOutNum", value = "转出前转出用户数量", paramType = "query"),
            @ApiImplicitParam(name = "afterOutNum", value = "转出后转出用户数量", paramType = "query"),
            @ApiImplicitParam(name = "beforeInNum", value = "转入前转入用户数量", paramType = "query"),
            @ApiImplicitParam(name = "afterInNum", value = "转入后转入用户数量", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "转账时间", paramType = "query")
    })
    @GetMapping(value = "/count")
    @ResponseBody
    public Integer count(@ApiIgnore JlbOreLog jlbOreLog) {
        if (jlbOreLog == null) {
            return jlbOreLogSV.count(new HashMap());
        } else {
            return jlbOreLogSV.count(jlbOreLog);
        }
    }


    /**
     * 创建JlbOreLog
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建JlbOreLog", notes = "创建JlbOreLog")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "inUserCode", value = "转入账户编码", paramType = "query"),
            @ApiImplicitParam(name = "num", value = "数量", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "类型 金兰宝  JLB ,矿石 ORE", paramType = "query"),
            @ApiImplicitParam(name = "event", value = "事件：转账 Transfer，复投 Re_Cast，押金 Deposit，押金返还 Deposit_Return", paramType = "query"),
            @ApiImplicitParam(name = "beforeOutNum", value = "转出前转出用户数量", paramType = "query"),
            @ApiImplicitParam(name = "afterOutNum", value = "转出后转出用户数量", paramType = "query"),
            @ApiImplicitParam(name = "beforeInNum", value = "转入前转入用户数量", paramType = "query"),
            @ApiImplicitParam(name = "afterInNum", value = "转入后转入用户数量", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "转账时间", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public BeanRet build(@ApiIgnore JlbOreLog jlbOreLog) {
        jlbOreLogSV.save(jlbOreLog);
        return BeanRet.create(true, "创建成功", jlbOreLog);
    }


    /**
     * 修改JlbOreLog
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改JlbOreLog", notes = "修改JlbOreLog")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "outUserCode", value = "转出账户编码", paramType = "query"),
            @ApiImplicitParam(name = "inUserCode", value = "转入账户编码", paramType = "query"),
            @ApiImplicitParam(name = "num", value = "数量", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "类型 金兰宝  JLB ,矿石 ORE", paramType = "query"),
            @ApiImplicitParam(name = "event", value = "事件：转账 Transfer，复投 Re_Cast，押金 Deposit，押金返还 Deposit_Return", paramType = "query"),
            @ApiImplicitParam(name = "beforeOutNum", value = "转出前转出用户数量", paramType = "query"),
            @ApiImplicitParam(name = "afterOutNum", value = "转出后转出用户数量", paramType = "query"),
            @ApiImplicitParam(name = "beforeInNum", value = "转入前转入用户数量", paramType = "query"),
            @ApiImplicitParam(name = "afterInNum", value = "转入后转入用户数量", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "转账时间", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public BeanRet modify(@ApiIgnore JlbOreLog jlbOreLog) {
        jlbOreLogSV.modify(jlbOreLog);
        return BeanRet.create(true, "修改成功", jlbOreLog);
    }

    /**
     * 删除JlbOreLog
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除JlbOreLog", notes = "删除JlbOreLog")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "outUserCode", value = "转出账户编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(Long id, String outUserCode) {
        jlbOreLogSV.delete(id, outUserCode);
        return BeanRet.create(true, "删除JlbOreLog成功");
    }

}
